package com.chifuyu.master;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Scanner;

@EqualsAndHashCode(callSuper = true)
@Data
public class Knight extends Character {
    private String NAME;
    private Integer MAX_HP;
    private Integer MAX_MP;
    private Integer CUR_HP;
    private Integer CUR_MP;
    private Integer BLOCK;
    private Integer SPEED;
    private boolean DEAD;

    public Knight(String name) {
        this.NAME = name;
        this.MAX_HP = 38;
        this.MAX_MP = 3;
        this.CUR_HP = 38;
        this.CUR_MP = 0;
        this.BLOCK = 3;
        this.SPEED = 12;
        this.DEAD = false;
    }

    @Override
    public void action(Character enemy) {
        System.out.print("Knight: ");
        System.out.println(this);
        System.out.println("1. Attack 2. Block 3. Final Skill");
        Scanner scanner = new Scanner(System.in);
        int actionCode = scanner.nextInt();
        switch (actionCode) {
            case 1:
                this.attack(enemy);
                break;
            case 2:
                this.block();
                break;
            case 3:
                this.finalSkill(enemy);
                break;
            default:
                System.out.println("ERROR INPUT. PLEASE RETRY!");
                this.action(enemy);
        }
    }

    @Override
    public void attack(Character enemy) {
        System.out.println("Knight attack!");
        System.out.println(enemy);
    }

    @Override
    public void block() {
        this.BLOCK += 2;
        System.out.println("Knight block!");
        System.out.println(this);
    }

    @Override
    public void finalSkill(Character enemy) {
        if (enemy.isDEAD()) {
            return;
        }
        enemy.decHP(8);
        System.out.println(enemy);
    }

    @Override
    public void moveOn() {

    }

    public boolean decHP(int decHP) {
        if (this.isDEAD() || this.CUR_HP < 0) {
            return false;
        } else {
            if (decHP >= this.CUR_HP) {
                this.CUR_HP = 0;
                this.DEAD = true;
            } else {
                this.CUR_HP -= decHP;
            }
            return true;
        }
    }

    public boolean incHP(int incHP) {
        if (this.isDEAD() || this.CUR_HP > MAX_HP) {
            return false;
        } else {
            if (incHP > MAX_HP - this.CUR_HP) {
                this.CUR_HP = MAX_HP;
            } else {
                this.CUR_HP += incHP;
            }
            return true;
        }
    }

    public boolean decMP(int decMP) {
        if (this.isDEAD() || this.CUR_MP < 0) {
            return false;
        } else {
            if (decMP > this.CUR_MP) {
                return false;
            } else {
                this.CUR_MP -= decMP;
                if (CUR_MP < 1) {
                    this.DEAD = true;
                }
            }
            return true;
        }
    }

    public boolean incMP(int incMP) {
        if (this.isDEAD() || this.CUR_MP > MAX_MP) {
            return false;
        } else {
            if (incMP > MAX_MP - this.CUR_MP) {
                this.CUR_MP = MAX_MP;
            } else {
                this.CUR_HP += incMP;
            }
            return true;
        }
    }

    @Override
    public String toString() {
        return "BL: " + BLOCK + " , HP: " + CUR_HP + "/" + MAX_HP + " , MP: " + CUR_MP + "/" + MAX_MP;
    }
}
